package com.terry.proxy.application.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.terry.proxy.application.cache.DBCache;
import com.terry.proxy.application.cache.DBServerCache;
import com.terry.proxy.common.Msg;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务代理控制层
 *
 * @author terry
 * @version 1.0
 * @date 2022/12/13 20:35
 */
// @Api(tags = "连接管理")
@RestController
@RequestMapping("/manager")
public class ManagerController extends ApiController {

    @GetMapping("/reloadClient")
    // @ApiOperation(value = "刷新客户端")
    public String reloadClient(String clientId){
        Msg tunnelMsg = new Msg();
        tunnelMsg.setData(DBServerCache.getClientTunnelAttr(clientId));
        tunnelMsg.setType(Msg.UPDATE_CLIENT_TUNNEL);
        // NettySocketProxyServer.clientProxyChannel.get(clientId).writeAndFlush(tunnelMsg);
        return "success";
    }

    @GetMapping("/getConfigByKey")
    public R getConfigByKey(@RequestParam String key){
        return success(DBCache.getConfigByKey(key));
    }
/*
    @Resource
    private ServerProxy serverProxy;*/

    @GetMapping("/reloadServer")
    // @ApiOperation(value = "刷新服务端")
    public String reloadClientAll(){
//        serverProxy.closeAll();
//        ThreadPoolExecutorUtil.execute(() -> {
//            serverProxy.init();
//        });
        return "success";
    }
}
